<?php

namespace App\Http\Controllers\user;

use App\Dao\BillsDao;
use App\Dao\RechargeDao;
use App\Dao\UsersDao;
use App\Dao\WithdrawalDao;
use App\Exceptions\SysExceptions;
use App\Services\Code;

class UsersController extends BaseController
{
    public function register(): array
    {
        $params = request()->all();
        UsersDao::register($params);
        return Code::message('',200);
    }
    //获取邮件验证码
     public function code(): array
     {
        $params = request()->all();
        UsersDao::code($params);
        return Code::message('',200);
    }
    //找回密码修改
     public function changepwd(): array
     {
        $params = request()->all();
        UsersDao::changepwd($params);
        return Code::message('',200);
    }
    
    
    public function login()
    {
        $params = request()->all();
        return Code::message('',200,UsersDao::login($params));
    }

    public function user_info(): array
    {
        return Code::message('',200,UsersDao::user_info([
            'user_id'=>getUserToken()
        ]));
    }

    public function user_spreads(): array
    {
        return Code::message('',200,UsersDao::user_spreads([
            'user_id'=>getUserToken()
        ]));
    }


    /**
     * @throws SysExceptions
     */
    public function user_to_activity(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        UsersDao::activity($params);
        return Code::message('',200);
    }

    //抛去充值记录
    public function bills(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken(),
            'type'=>0
        ]);
        return Code::message('',200,BillsDao::bills_page($params));
    }

    /**
     * @throws SysExceptions
     */
    public function setPayPass(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        UsersDao::setPayPass($params);
        return Code::message();
    }


    public function setEmailUser(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        UsersDao::setEmail($params);
        return Code::message();
    }

    public function levelUpU(){
        $params = request()->all();
        UsersDao::levelUpU($params);
        return Code::message();
    }


    public function setPayPassUser(): array
    {
        $params = request()->all();
        UsersDao::setPayPassUser($params);
        return Code::message();
    }


    /**
     * @throws SysExceptions
     */
    public function recharge(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        UsersDao::recharge($params);
        return Code::message('',200);
    }


    public function recharges(): array
    {
        return Code::message('',200,RechargeDao::pager([
            'user_id'=>getUserToken()
        ]));
    }


    public function withwals(): array
    {
        return Code::message('',200,WithdrawalDao::pager([
            'user_id'=>getUserToken()
        ]));
    }

    public function withdrawal(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        UsersDao::withdrawal($params);
        return Code::message('success',200);
    }

    public function setPassword(): array
    {
        $params = array_merge(request()->all(),[
            'user_id'=>getUserToken()
        ]);
        UsersDao::setPass($params);
        return Code::message();
    }

}
